#include"MainWindow.h"
#include "screen.h"
#include<qdebug.h>
#include<QBitmap>
#include<qpainter.h>
Screen::Screen(QWidget *parent,MainWindow *p) : QWidget(parent)
{
    prt=p;//传入父窗口指针，以便调用数据
    this->setGeometry(50, 50, 640, 300);

    QPalette pal(this->palette());
     //设置背景白色
    pal.setColor(QPalette::Background, QColor(220,220,220));
    this->setAutoFillBackground(true);
    this->setPalette(pal);
    //圆角窗口
    QBitmap bmp(this->size());
    bmp.fill();
    QPainter pt(&bmp);
    pt.setPen(Qt::NoPen);
    pt.setBrush(Qt::black);
    pt.drawRoundedRect(bmp.rect(),10,10);
    setMask(bmp);

}

void Screen::paintEvent(QPaintEvent *event){
    QPainter painter(this);
    //QPainter painter1(this);
    //painter.setBrush(Qt::white);
    QFont font;
    font.setPointSize(35);
    painter.setFont(font);
    painter.drawText(15,115,"𝄞");
    painter.drawText(15,250,"𝄢");

    font.setPointSize(8);
    painter.setFont(font);
    //显示五线谱
    for(int i=0;i<5;i++)
    {
        painter.drawLine(QPoint(0,35+20*i),QPoint(640,35+20*i));
        painter.drawLine(QPoint(0,185+20*i),QPoint(640,185+20*i));
    }
    if(prt->isActive[12]==1){//C3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(190,235),7,4);
    }
    if(prt->isActive[13]==1){//#C3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(190,235),7,4);
        painter.drawText(QPoint(172,240),"#");
    }
    if(prt->isActive[14]==1){//D3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(210,225),7,4);
    }
    if(prt->isActive[15]==1){//#D3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(210,225),7,4);
        painter.drawText(QPoint(192,230),"#");
    }
    if(prt->isActive[16]==1){//E3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(230,215),7,4);
    }
    if(prt->isActive[17]==1){//F3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(250,205),7,4);
    }
    if(prt->isActive[18]==1){//#F3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(250,205),7,4);
        painter.drawText(QPoint(232,210),"#");
    }
    if(prt->isActive[19]==1){//G3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(270,195),7,4);
    }
    if(prt->isActive[20]==1){//#G3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(270,195),7,4);
        painter.drawText(QPoint(252,200),"#");
    }
    if(prt->isActive[21]==1){//A3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(290,185),7,4);
    }
    if(prt->isActive[22]==1){//#A3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(290,185),7,4);
        painter.drawText(QPoint(272,190),"#");
    }
    if(prt->isActive[23]==1){//B3
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(310,175),7,4);
    }
    if(prt->isActive[24]==1){//C4
        painter.setBrush(Qt::black);
        painter.drawLine(320,135,340,135);
        painter.drawEllipse(QPoint(330,135),7,4);
    }
    if(prt->isActive[25]==1){//#C4
        painter.setBrush(Qt::black);
        painter.drawLine(320,135,340,135);
        painter.drawEllipse(QPoint(330,135),7,4);
        painter.drawText(QPoint(312,140),"#");//左移18，下移5
    }
    if(prt->isActive[26]==1){//D4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(350,125),7,4);
    }
    if(prt->isActive[27]==1){//#D4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(350,125),7,4);
        painter.drawText(QPoint(332,130),"#");
    }
    if(prt->isActive[28]==1){//E4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(370,115),7,4);
    }
    if(prt->isActive[29]==1){//F4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(390,105),7,4);
    }
    if(prt->isActive[30]==1){//#F4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(390,105),7,4);
        painter.drawText(QPoint(372,110),"#");
    }
    if(prt->isActive[31]==1){//G4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(410,95),7,4);
    }
    if(prt->isActive[32]==1){//#G4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(410,95),7,4);
        painter.drawText(QPoint(392,100),"#");
    }
    if(prt->isActive[33]==1){//A4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(430,85),7,4);
    }
    if(prt->isActive[34]==1){//#A4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(430,85),7,4);
        painter.drawText(QPoint(412,90),"#");
    }
    if(prt->isActive[35]==1){//B4
        painter.setBrush(Qt::black);
        painter.drawEllipse(QPoint(450,75),7,4);
    }

}

void Screen::scrSlot(){
    update();
}
